﻿
using System;
using System.Windows;
using System.Windows.Forms;
using AmazonGlacierGUI.Core;
using AmazonGlacierGUI.UI.ViewModels;
using AmazonGlacierGUI.UI.Views;
using MessageBox = System.Windows.MessageBox;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace AmazonGlacierGUI.UI.Infrastructure
{
    //21-Nov-2011 Priyan R
    public class UIHelper
    {
        /*(From documentation) Filter string should contain a description of the filter, followed by a vertical bar and the filter pattern.
         * Must also separate multiple filter description and pattern pairs by a vertical bar. Must separate multiple extensions 
         * in a filter pattern with a semicolon. Example: "Image files (*.bmp, *.jpg)|*.bmp;*.jpg|All files (*.*)|*.*"
         */
        public static void ShowOpenFileDialog(string filterString, Action<string> onSelected,
                Action onCancelled)
        {
            ShowOpenFileDialog(filterString, false, (p) => onSelected(p[0]), onCancelled);
        }
        public static void ShowOpenFileDialog(string filterString,bool multiSelect,Action<string[]> onSelected,
                Action onCancelled)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Multiselect = multiSelect;
            dlg.Filter = filterString;
            if (dlg.ShowDialog().Value)
            {
                onSelected(dlg.FileNames);
            }
            else
            {
                onCancelled();
            }
        }
        public static void ShowSelectFolderDialog(Action<string> onSelected,
              Action onCancelled)
        {
            var dialog = new System.Windows.Forms.FolderBrowserDialog();
            var result = dialog.ShowDialog();            
            if (result==DialogResult.OK)
            {
                onSelected(dialog.SelectedPath);
            }
            else
            {
                onCancelled();
            }
        }
        public  static void ShowConfirm(string message,Action<bool> callback)
        {
            callback(MessageBox.Show(message, Constants.AppTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes);
        }
        public  static void ShowMessage(string message,Action callback)
        {
            MessageBox.Show(message, Constants.AppTitle, MessageBoxButton.OK, MessageBoxImage.Information);            
            if (callback!=null) callback();
        }
        public static void ShowError(string message, Action callback)
        {
            MessageBox.Show(message, Constants.AppTitle, MessageBoxButton.OK, MessageBoxImage.Error);
            if (callback != null) callback();
        }
        public static void ShowSettingsScreen()
        {
            new SettingsView().ShowDialog();
        }
        public static void ShowUploadScreen(string[] files)
        {
            new UploadView(new UploadViewModel(files)).Show();
        }
        public static void ShowVaultBrowser(VaultBrowserViewModel vm)
        {
            new VaultBrowser(vm).ShowDialog();
        }
        public static void ShowCreateNewVault(CreateNewVaultViewModel vm)
        {
            new CreateNewVaultView(vm).ShowDialog();
        }

        public static ArchiveSelectSourceViewModel ShowArchiveSelectSource()
        {
            var vm=new ArchiveSelectSourceView();
            vm.ShowDialog();
            return (ArchiveSelectSourceViewModel) vm.DataContext;
        }
        public static void ShowDownloadFromHistory()
        {
            new DownloadArchiveFromUploadHistoryView().Show();
        }
        public static void ShowDownloadArchiveByArchiveId()
        {
            new DownloadArchiveByArchiveId().Show();
        }
        public static void ShowDownloadArchiveFromAmazonInventory()
        {
            new DownloadArchiveFromAmazonInventoryView().Show();

        }
        public static void ShowJobDetails(JobDetailsViewModel vm)
        {
            new JobDetailsView(vm).Show();

        }
        
    }
}
